<html>
<head><meta charset="utf-8"><title>Properly qualify argument types in generated functions · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html">Properly qualify argument types in generated functions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="194930399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194930399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194930399">(Apr 22 2020 at 13:32)</a>:</h4>
<p>I'm trying to tackle the next issue of the add_function assist: properly qualifying the types of the generated arguments! (see currently ignored <a href="https://github.com/rust-analyzer/rust-analyzer/blob/cb0a24104cc5ad15d40e47d92fbdb63683adf8a0/crates/ra_assists/src/handlers/add_function.rs#L533" title="https://github.com/rust-analyzer/rust-analyzer/blob/cb0a24104cc5ad15d40e47d92fbdb63683adf8a0/crates/ra_assists/src/handlers/add_function.rs#L533">test case</a> for that)<br>
I guess <a href="https://github.com/rust-analyzer/rust-analyzer/blob/cb0a24104cc5ad15d40e47d92fbdb63683adf8a0/crates/ra_hir/src/code_model.rs#L287" title="https://github.com/rust-analyzer/rust-analyzer/blob/cb0a24104cc5ad15d40e47d92fbdb63683adf8a0/crates/ra_hir/src/code_model.rs#L287"><code>code_model::Module::find_use_path</code></a> should be able to handle this, but I have no idea how to get the corresponding <code>ItemInNs</code> for a <code>Type</code> <a href="https://github.com/rust-analyzer/rust-analyzer/blob/cb0a24104cc5ad15d40e47d92fbdb63683adf8a0/crates/ra_assists/src/handlers/add_function.rs#L180" title="https://github.com/rust-analyzer/rust-analyzer/blob/cb0a24104cc5ad15d40e47d92fbdb63683adf8a0/crates/ra_assists/src/handlers/add_function.rs#L180">here</a> so I can call that method.<br>
Any help?</p>



<a name="194959526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194959526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194959526">(Apr 22 2020 at 16:51)</a>:</h4>
<p>I probably want to use <code>QualifyPaths</code>... the API looks quite usable, I'm doing something wrong though. I'm gonna <code>dbg!</code>-explore it a bit and probably find my mistake soon :)</p>



<a name="194962967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194962967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194962967">(Apr 22 2020 at 17:15)</a>:</h4>
<p>Okay, I think I know what the problem is, unfortunately I'm stumped.<br>
<a href="https://github.com/rust-analyzer/rust-analyzer/blob/cb0a24104cc5ad15d40e47d92fbdb63683adf8a0/crates/ra_assists/src/ast_transform.rs#L132" title="https://github.com/rust-analyzer/rust-analyzer/blob/cb0a24104cc5ad15d40e47d92fbdb63683adf8a0/crates/ra_assists/src/ast_transform.rs#L132"><code>self.source_scope.resolve_hir_path(&amp;hir_path?)</code></a> returns <code>None</code>, so the <code>source_scope</code> I'm passing to <code>QualifyPaths</code> can't resolve the path.<br>
I'm not really sure what <code>SemanticsScope</code> I need to pass.<br>
Right now I'm creating it by calling <code>ctx.sema.scope()</code> with the <code>CallExpr</code> where the assist was triggered.<br>
Do I need to find the scope where the argument type was defined instead?</p>



<a name="194964963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194964963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194964963">(Apr 22 2020 at 17:29)</a>:</h4>
<p>hmm ideally I think we'd want something that prints a type with qualified paths, but that doesn't exist yet</p>



<a name="194965064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194965064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194965064">(Apr 22 2020 at 17:30)</a>:</h4>
<p>but probably we can't get around that in this case</p>



<a name="194965249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194965249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194965249">(Apr 22 2020 at 17:31)</a>:</h4>
<p>i.e. it'd be somewhat like <code>HirDisplay</code>, but qualify paths, only produce things that are valid rust code (i.e. no <code>{unknown}</code> or closure types), and maybe return a syntax node instead of a string</p>



<a name="194966508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194966508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194966508">(Apr 22 2020 at 17:40)</a>:</h4>
<p>yeah i would like to have something like that :) i wasn't sure if the existing functionality covered that usecase already - it seems similar to generating qualified paths in the <code>add_missing_impl_members</code> assist <a href="https://github.com/rust-analyzer/rust-analyzer/blob/cb0a24104cc5ad15d40e47d92fbdb63683adf8a0/crates/ra_assists/src/handlers/add_missing_impl_members.rs#L345" title="https://github.com/rust-analyzer/rust-analyzer/blob/cb0a24104cc5ad15d40e47d92fbdb63683adf8a0/crates/ra_assists/src/handlers/add_missing_impl_members.rs#L345">(example)</a></p>



<a name="194966734"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194966734" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194966734">(Apr 22 2020 at 17:42)</a>:</h4>
<p>I'm currently trying to find out why the scope I'm passing to <code>resolve_hir_path</code> doesn't find the path to the type as it's not really obvious to me - I reached <code>path_resolution::resolve_path_fp_with_macro</code> and my brain is full...</p>



<a name="194967395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194967395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194967395">(Apr 22 2020 at 17:48)</a>:</h4>
<p>the difference is that <code>add_missing_impl_members</code> just copies the written types from the trait declaration and qualifies them, but your assist can't do that</p>



<a name="194967594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194967594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194967594">(Apr 22 2020 at 17:49)</a>:</h4>
<blockquote>
<p>I'm currently trying to find out why the scope I'm passing to <code>resolve_hir_path</code> doesn't find the path to the type as it's not really obvious to me</p>
</blockquote>
<p>if you're trying to resolve something you got from <code>HirDisplay</code>ing a type, I think that's unlikely to work</p>



<a name="194967657"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194967657" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194967657">(Apr 22 2020 at 17:50)</a>:</h4>
<p>that's unfair <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="194967706"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194967706" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194967706">(Apr 22 2020 at 17:50)</a>:</h4>
<p>I mean, if it resolved then you wouldn't need to qualify it...</p>



<a name="194967749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194967749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194967749">(Apr 22 2020 at 17:51)</a>:</h4>
<p>but it even fails in my testcase where the displayed type matches the definition</p>



<a name="194967814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194967814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194967814">(Apr 22 2020 at 17:51)</a>:</h4>
<p>hmm that's a very good point</p>



<a name="194967841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194967841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194967841">(Apr 22 2020 at 17:51)</a>:</h4>
<p>also, the <code>Semantics</code> stuff doesn't really work with syntax nodes you built yourself</p>



<a name="194967874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194967874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194967874">(Apr 22 2020 at 17:51)</a>:</h4>
<p>ok the failures start to make sense</p>



<a name="194968038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194968038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194968038">(Apr 22 2020 at 17:52)</a>:</h4>
<p>so, there's definitely some missing functionality somewhere in <code>hir</code> for that, right?</p>



<a name="194968116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194968116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194968116">(Apr 22 2020 at 17:53)</a>:</h4>
<p>yes</p>



<a name="194968212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194968212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194968212">(Apr 22 2020 at 17:54)</a>:</h4>
<p>so I want to take a <code>Type</code>, find out where it's defined (does that already exist?) and compute a path from the module where the function will be generated to the type definition.<br>
and display that</p>



<a name="194968373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194968373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194968373">(Apr 22 2020 at 17:55)</a>:</h4>
<p>i'm gonna try to get something working, any guidance is very welcome :)</p>



<a name="194968564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194968564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194968564">(Apr 22 2020 at 17:57)</a>:</h4>
<p>well, the idea would be to either build something similar to <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_hir_ty/src/display.rs" title="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_hir_ty/src/display.rs">HirDisplay</a>, or add a parameter to it that makes it qualify paths</p>



<a name="194968606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194968606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194968606">(Apr 22 2020 at 17:57)</a>:</h4>
<p>it would need the <code>ModuleId</code> from where it's supposed to qualify the paths</p>



<a name="194968658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194968658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194968658">(Apr 22 2020 at 17:57)</a>:</h4>
<p>and then it could use <code>find_path</code> to find the proper path</p>



<a name="194968788"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194968788" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194968788">(Apr 22 2020 at 17:58)</a>:</h4>
<p>the relevant place for qualifying structs etc. would be <a href="https://github.com/rust-analyzer/rust-analyzer/blob/3f1f3a835a07983344f6f3becf7a0c32b96d68bc/crates/ra_hir_ty/src/display.rs#L194" title="https://github.com/rust-analyzer/rust-analyzer/blob/3f1f3a835a07983344f6f3becf7a0c32b96d68bc/crates/ra_hir_ty/src/display.rs#L194">here</a>, instead of just taking the name you'd use <code>find_path</code></p>



<a name="194969063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194969063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194969063">(Apr 22 2020 at 18:00)</a>:</h4>
<p>this is all behind the "code model" facade, so you're working with <code>Ty</code> and <code>ModuleId</code> and so on instead of <code>Type</code> and <code>Module</code>, and you need to expose it in <code>Type</code> in the end</p>



<a name="194969893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194969893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194969893">(Apr 22 2020 at 18:07)</a>:</h4>
<p>I think in the end we'll want a separate facility for this, since printing types 'properly' has various ways it can fail (the type isn't reachable from where we are, the type contains unnameable types...), so we'll want it to return <code>Option</code> or maybe a <code>Result</code> in the end (and while we're at it we could have it return a syntax node instead of a string), but as a first step it's probably easier to just hack it into the existing thing</p>



<a name="194972306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194972306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194972306">(Apr 22 2020 at 18:27)</a>:</h4>
<p>thanks a lot! i'm going to digest this now :)</p>



<a name="194991390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/194991390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#194991390">(Apr 22 2020 at 21:06)</a>:</h4>
<p>Holy crap it works :) thanks!</p>



<a name="195215615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/195215615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#195215615">(Apr 24 2020 at 16:53)</a>:</h4>
<p>I see what you meant now, returning <code>Option</code> or <code>Result</code> is really hard with the way <code>ToString</code> uses <code>fmt::Display</code>, you can't even go super hacky and abuse <code>fmt::Result</code> :(<br>
How about maybe parametrizing the new fallible parts with a trait where the old implementation has <code>type Error = Infallible</code> and the new implementation (used for rendering code into source files) gets an actual error type? then only <code>HirDisplayWrapper&lt;Old&gt;</code> would implement <code>fmt::Display</code>, and <code>HirDisplayWrapper&lt;New&gt;</code> would get it's own <code>fn render(&amp;self) -&gt; Option&lt;String&gt;</code> (or other return type)<br>
The existing implementations of <code>hir_fmt</code> would still need to be changed of course, but maybe that way most of the printing logic could be defined only once</p>



<a name="195473102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/195473102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#195473102">(Apr 27 2020 at 20:48)</a>:</h4>
<p>I went ahead and tried that approach: <a href="https://github.com/rust-analyzer/rust-analyzer/pull/4175" title="https://github.com/rust-analyzer/rust-analyzer/pull/4175">https://github.com/rust-analyzer/rust-analyzer/pull/4175</a></p>



<a name="196049977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/196049977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#196049977">(May 02 2020 at 12:40)</a>:</h4>
<p>Hey Florian,<br>
I'm not sure about your <a href="https://github.com/rust-analyzer/rust-analyzer/pull/4175#discussion_r416809207" title="https://github.com/rust-analyzer/rust-analyzer/pull/4175#discussion_r416809207">comment</a> about using an enum instead of a trait to customize the <code>HirDisplay</code> behaviour.<br>
Would you recommend to make <code>hir_fmt</code> always return the sum error type that's currently called <code>FormatSourceCodeError</code> and assert that the call to <code>hir_fmt</code> in the <code>Display</code> implementation didn't return any error other than <code>fmt::Error</code>?<br>
That's the only way to use an enum instead of a trait I could think of, did I miss something?</p>



<a name="196051017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/196051017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#196051017">(May 02 2020 at 13:12)</a>:</h4>
<p>yeah, that's what I was thinking</p>



<a name="196051310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Properly%20qualify%20argument%20types%20in%20generated%20functions/near/196051310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Properly.20qualify.20argument.20types.20in.20generated.20functions.html#196051310">(May 02 2020 at 13:20)</a>:</h4>
<p>Alright that makes sense, thanks for the quick reply. I'm gonna change that then :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>